/*
 * @Author: luojianfeng
 * @Date: 2022-12-09 09:16:40
 * @LastEditTime: 2023-03-17 16:59:24
 * @LastEditors: luojianfeng
 * @Description:
 */
import { language as mysqlLanguage } from 'monaco-editor/esm/vs/basic-languages/mysql/mysql.js'
import 'monaco-editor/esm/vs/basic-languages/mysql/mysql.contribution.js'
import { Monaco } from '../types'
export default function registerSnippets(monaco: Monaco) {
  monaco.languages.registerCompletionItemProvider('mysql', {
    triggerCharacters: [' ', '.'],
    provideCompletionItems(model, position) {
      const suggestions: any[] = []
      const json = sessionStorage.getItem('hite')
      if (json) {
        JSON.parse(json).forEach((item: any) => {
          suggestions.push({
            label: item.name,
            kind: monaco.languages.CompletionItemKind.Keyword,
            insertText: item.name
          })
        })
      }
      mysqlLanguage.keywords.forEach((item: any) => {
        suggestions.push({
          label: item,
          kind: monaco.languages.CompletionItemKind.Keyword,
          insertText: item
        })
      })
      mysqlLanguage.operators.forEach((item: any) => {
        suggestions.push({
          label: item,
          kind: monaco.languages.CompletionItemKind.Operator,
          insertText: item
        })
      })
      mysqlLanguage.builtinFunctions.forEach((item: any) => {
        suggestions.push({
          label: item,
          kind: monaco.languages.CompletionItemKind.Function,
          insertText: item
        })
      })
      mysqlLanguage.builtinVariables.forEach((item: any) => {
        suggestions.push({
          label: item,
          kind: monaco.languages.CompletionItemKind.Variable,
          insertText: item
        })
      })
      return {
        suggestions: suggestions
      }
    }
  })
}
